﻿/*
 * Copyright © 2011 Tristan Reeves, treeves@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using Sprinkles.Tests.TestClasses;
using System.Collections.Generic;

namespace Sprinkles.Tests.DeploymentHosts
{
    public class AutoArgumentsHost : DeploymentHost
    {
        public interface IInterfaceWithName
        {
            string Name { get; set; }
        }
        public interface IInterface1 : IInterfaceWithName
        {
            string Name { get; set; }
        }
        public interface IInterface2 : IInterfaceWithName
        {
            string Name { get; set; }
        }
        public interface IInterface3 : IInterfaceWithName
        {
            string Name { get; set; }
        }
        public interface IInterface4 : IInterfaceWithName
        {
            string Name { get; set; }
        }
        public interface IInterface5 : IInterfaceWithName
        {
            string Name { get; set; }
        }

        public class Implementor1 : IInterface1
        {
            public string Name { get; set; }
        }
        public class Implementor2 : IInterface2
        {
            public string Name { get; set; }
        }
        public class Implementor3 : IInterface3
        {
            public string Name { get; set; }
        }
        public class Implementor4 : IInterface4
        {
            public string Name { get; set; }
        }
        public class Implementor5 : IInterface5
        {
            public string Name { get; set; }
        }

        public class X
        {
            public List<IInterfaceWithName> Objects = new List<IInterfaceWithName>();
            public X(IInterface1 a)
            {
                Objects.Add(a);
            }
            public X(IInterface1 a, IInterface2 b)
            {
                Objects.Add(a);
                Objects.Add(b);
            }
            public X(IInterface1 a, IInterface2 b, IInterface3 c)
            {
                Objects.Add(a);
                Objects.Add(b);
                Objects.Add(c);
            }
            public X(IInterface1 a, IInterface2 b, IInterface3 c, IInterface4 d)
            {
                Objects.Add(a);
                Objects.Add(b);
                Objects.Add(c);
                Objects.Add(d);
            }
            public X(IInterface1 a, IInterface2 b, IInterface3 c, IInterface4 d, IInterface5 e)
            {
                Objects.Add(a);
                Objects.Add(b);
                Objects.Add(c);
                Objects.Add(d);
                Objects.Add(e);
            }
        }

        private string Qualify(string name)
        {
            return "AutoArgumentsHost." + name;
        }

        protected override void RegisterDeployments()
        {
            Register<Implementor1>()
                .IsDefaultFor<IInterface1>()
                .Property(x => x.Name).SetLiteral("Name1")
                .Done();
            Register<Implementor2>()
                .IsDefaultFor<IInterface2>()
                .Property(x => x.Name).SetLiteral("Name2")
                .Done();
            Register<Implementor3>()
                .IsDefaultFor<IInterface3>()
                .Property(x => x.Name).SetLiteral("Name3")
                .Done();
            Register<Implementor4>()
                .IsDefaultFor<IInterface4>()
                .Property(x => x.Name).SetLiteral("Name4")
                .Done();
            Register<Implementor5>()
                .IsDefaultFor<IInterface5>()
                .Property(x => x.Name).SetLiteral("Name5")
                .Done();

            Register<X>(Qualify("1"))
                .CreatedBy.Constructor<IInterface1>
                ((a) => new X(a))
                .SetAuto()
                .Done();
            Register<X>(Qualify("2"))
                .CreatedBy.Constructor<IInterface1, IInterface2>
                ((a, b) => new X(a, b))
                .SetAuto()
                .SetAuto()
                .Done();
            Register<X>(Qualify("3"))
                .CreatedBy.Constructor<IInterface1, IInterface2, IInterface3>
                ((a, b, c) => new X(a, b, c))
                .SetAuto()
                .SetAuto()
                .SetAuto()
                .Done();
            Register<X>(Qualify("4"))
                .CreatedBy.Constructor<IInterface1, IInterface2, IInterface3, IInterface4>
                ((a, b, c, d) => new X(a, b, c, d))
                .SetAuto()
                .SetAuto()
                .SetAuto()
                .SetAuto()
                .Done();
            Register<X>(Qualify("5"))
                .CreatedBy.Constructor<IInterface1, IInterface2, IInterface3, IInterface4, IInterface5>
                ((a, b, c, d, e) => new X(a, b, c, d, e))
                .SetAuto()
                .SetAuto()
                .SetAuto()
                .SetAuto()
                .SetAuto()
                .Done();
        }

        protected override bool Include
        {
            get { return (UserContext == "construction-config-1") && ALLOW; }
        }
        public static bool ALLOW = true;
    }
}
